import 'package:shared_preferences/shared_preferences.dart';
import 'const_config.dart';
///简单存取工具类
class SharedPreferencesUtils{
  static SharedPreferences _spf;
  static Future init() async {
    _spf = await SharedPreferences.getInstance();
  }

  ///获取token
  String getToken() {
    var token = _spf?.getString(ConstConfig.ACCES_TOKEN);
    if (token == null) {
      token = "";
    }
    return token;
  }

  ///存token
  String saveToken(String token) {
    _spf?.setString(ConstConfig.ACCES_TOKEN,token);
  }


  ///获取username
  String getUserName() {
    var token = _spf?.getString(ConstConfig.USER_NAME);
    if (token == null) {
      token = "";
    }
    return token;
  }

  ///存username
  String saveUsername(String token) {
    _spf?.setString(ConstConfig.USER_NAME,token);
  }
}